package com.roger.myHome.util;


import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SystemUtil {

    @Resource
    private UserHelper userHelper;

    private static UserHelper myUserHelper;

    @PostConstruct
    public void init(){
        myUserHelper = userHelper;
    }

    private static List<String> MENU_URL_LIST = new ArrayList<>();

    public static void setMenuUrlList(List<String> list){
        MENU_URL_LIST.addAll(list);
    }

    public static List<String> getMenuUrlList(){
        return MENU_URL_LIST;
    }

    public static Long getUserFromSession(HttpServletRequest request){
        //HttpSession session = request.getSession();
        try{
            Long id = myUserHelper.getLoginUser(request).getId();
//            if(session.getAttribute(Constants.LOGIN_USER) == null){
//                throw new Exception("session is out of service");
//            }
//            return (LoginUser) session.getAttribute(Constants.LOGIN_USER);
            if(id == null){
                throw new Exception("session is out of service");
            }
            return id;
        }catch(Exception e){
            System.out.println(e.getMessage());
            return null;
        }
    }

    public static Long getId(){
        Random random = new Random();
        int workerId = random.nextInt(10);
        int datacenterId = random.nextInt(10);
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(workerId, datacenterId);
        return idWorker.nextId() + Math.abs(random.nextLong());
    }

    public enum Day {
        SUNDAY, MONDAY, TUESDAY,
        WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;
    }

    static void printNumber(Day day) {
        int numLetters = 0;
        switch (day) {
            case MONDAY:
                numLetters = 1;
                break;
            case SUNDAY:
                numLetters = 6;
                break;
            case TUESDAY:
                numLetters = 7;
                break;
            case THURSDAY:
                numLetters = 4;
                break;
            case SATURDAY:
                numLetters = 8;
                break;
            case WEDNESDAY:
                numLetters = 3;
                break;
            default:
                throw new IllegalStateException("Invalid day: " + day);
        }
        System.out.println(numLetters);
    }


    public static void main(String[] args) {
        printNumber(Day.FRIDAY);
    }

}
